#ifndef __MY_TYPEDEF_H
#define __MY_TYPEDEF_H

#ifdef __cplusplus
extern "C" {
#endif
#include "stm32f1xx_hal.h"

/**
 * @brief Ret
 */
#define MY_OK 0
#define MY_ERROR 1
#define MY_BUSY 2
#define MY_TIMEOUT 3

#define MY_YES	0
#define MY_NO	1

#define MY_OPEN		0
#define MY_CLOSE	1

#define MY_ENABLE	0
#define MY_DISABLE	1

// used with UU16
#define LSB 0
#define MSB 1

// used with UU32 (b0 is least-significant byte)
#define b0 0
#define b1 1
#define b2 2
#define b3 3
#define b4 4
#define b5 5
#define b6 6
#define b7 7

/**
 * @brief uu16
 */
typedef union uu16
{
	uint16_t u16;
	int16_t s16;
	uint8_t u8[2];
	int8_t s8[2];
} uu16;

/**
 * @brief uu32
 */
typedef union uu32
{
	uint32_t u32;
	int32_t s32;
	uu16 uu16[2];
	uint16_t u16[2];
	int16_t s16[2];
	uint8_t u8[4];
	int8_t s8[4];
    float f;
} uu32;

/**
 * @brief uu64
 */
typedef union uu64
{
	uint64_t u64;
	int64_t s64;
	uint32_t u32[2];
	int32_t s32[2];
	uu16 uu16[4];
	uint16_t u16[4];
	int16_t s16[4];
	uint8_t u8[8];
	int8_t s8[8];
	float f;
} uu64;

/**
 * @brief TimeCtrl_TypeDef
 */
typedef struct
{
	FunctionalState Flag;
	uu32 Count;
    uu32 ReloadValue;
} TimeCtrl_TypeDef;

/**
 * @brief TimeCntCtrl_TypeDef
 */
typedef struct
{
	FunctionalState Flag;
	uu32 Ms;
	uint16_t Cnt;
} TimeCntCtrl_TypeDef;

typedef struct Buffer_s
{
    uint8_t *Buf;
    uint16_t Length;
} Buffer_t;

#ifdef __cplusplus
}
#endif
#endif /* __MY_TYPEDEF_H */
